package com.example.demo.mapper;

import com.example.demo.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 三石
* @description 针对表【role(角色表)】的数据库操作Mapper
* @createDate 2024-05-06 21:39:48
* @Entity com.example.demo.domain.Role
*/
@Mapper
public interface RoleMapper extends BaseMapper<Role> {
    @Select("<script>"+
            "select id,rolename from role where id in "+
            "<foreach collection='roleIds' item='item' open='(' close=')' separator=','>"+
            "#{item}" +
            "</foreach>" +
            "</script> ")
    List<Role> selectRoleByIds(@Param("roleIds") List<Long> roleIds);

    /**
     * 根据角色id集合查询权限id集合
     * @param roleIds 角色id列表
     * @return 权限id列表
     */
    @Select("<script>"+
            "select distinct auth_id from role left join role_auth on role.id = role_auth.role_id where role.id in "+
            "<foreach collection='roleIds' item='item' open='(' close=')' separator=','>"+
            "#{item}" +
            "</foreach>" +
            "</script> ")
    List<Long> selectAuthorIdsByIds(@Param("roleIds") List<Long> roleIds);

}




